﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using SOAPServices.Dominio;
using SOAPServices.Persistencia;

namespace SOAPServices
{
    // NOTA: puede usar el comando "Rename" del menú "Refactorizar" para cambiar el nombre de clase "Cobros" en el código, en svc y en el archivo de configuración a la vez.
    public class Cobros : ICobros
    {
        //private VehiculoDAO vehiculoDAO = null;
        //private VehiculoDAO VehiculoDAO
        //{
        //    get
        //    {
        //        if (vehiculoDAO == null)
        //            vehiculoDAO = new VehiculoDAO();
        //        return vehiculoDAO;
        //    }
        //}

        //Invocamos el servicio Vehiculos
        Vehiculos vehiculo = new Vehiculos();

        private TicketDAO ticketDAO = null;
        private TicketDAO TicketDAO
        {
            get
            {
                if (ticketDAO == null)
                    ticketDAO = new TicketDAO();
                return ticketDAO;
            }
        }

        private VehiculoTicketDAO vehiculoTicketDAO = null;
        private VehiculoTicketDAO VehiculoTicketDAO
        {
            get
            {
                if (vehiculoTicketDAO == null)
                    vehiculoTicketDAO = new VehiculoTicketDAO();
                return vehiculoTicketDAO;
            }
        }

        public Ticket generarTicket(DateTime fecha)
        {
            Ticket ticketNuevo=new Ticket(){
                Fecha=fecha,
            };
            return TicketDAO.Crear(ticketNuevo);
        }

        public VehiculoTicket registrarCobro(int placa, int numero, double peaje, double detraccion, double evacion)
        {
            //obtener numero ticket
            Ticket ticketExistente = TicketDAO.Obtener(numero);
            //obtener numero vehiculo
            Vehiculo vehiculoExistente = vehiculo.obtenerVehiculo(placa);

            VehiculoTicket nuevoCobro = new VehiculoTicket()
            {
                Vehiculo = vehiculoExistente,
                Ticket = ticketExistente,
                Peaje = peaje,
                Detraccion = detraccion,
                Evacion=evacion,
            };
            return VehiculoTicketDAO.Crear(nuevoCobro);
        }



        public VehiculoTicket ObtenerDetraccion(int item)
        {
            return VehiculoTicketDAO.Obtener(item);
        }
    }
}
